﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tools.Framework
{
    /// <summary>
    /// 接口功能注释说明
    /// </summary>
    public class DescriptionSummary : Attribute
    {
        
        public class Paramter
        {
            /// <summary>
            /// 参数名称
            /// </summary>
            public string Name { set; get; }
            /// <summary>
            /// 类型
            /// </summary>
            public Type Type { set; get; }

            /// <summary>
            /// 可为空
            /// </summary>
            public bool IsNull { set; get; }

            /// <summary>
            /// 说明
            /// </summary>
            public string Summary { set; get; }
        }

        /// <summary>
        /// 结果模板
        /// </summary>
        public static string Description(string methodName, List<Paramter> paramters)
        {
            
                string html = string.Format("<h4>{0}</h4>",methodName);
                string trs = "<tr><td>参数</td><td>类型</td><td>是否可空</td><td>说明</td></tr>";
                paramters.ForEach(a =>
                {
                    trs += string.Format(Htmltr, a.Name, a.Type.Name,a.IsNull ,a.Summary);
                });
                return string.Format(Htmltemplate, html);
        }


        private const string Htmltemplate = @"<table>{0}</table><hr>";

        private const string Htmltr = "@<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>";

    }
}
